package com.pc.controller;

import com.pc.enrty.User;
import com.pc.service.UserService;
import com.pc.util.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/pc/sysUserAction")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private ResultObject result;

    /**
     * 登录,传递用户名,uid
     * @return
     */
    @RequestMapping("login")
    public ResultObject login(User user) {
        ArrayList<User> list = userService.findByUsernameAndPassword(user);
        result.setStatus(400);
        result.setResult(list);
        return result;
    }

    @RequestMapping("loginreg")
    public ResultObject loginreg(User user) {
        ArrayList<User> list = userService.findByUsername(user);
        result.setStatus(400);
        result.setResult(list);
        return result;
    }

    /**
     * 注册
     * @return
     */
    @RequestMapping("register")
    public ResultObject register(User user){
        boolean b = userService.addUser(user);
        if(b){
            result.setStatus(400);
            result.setResult("注册成功");
        }else{
            result.setStatus(406);
            result.setResult("注册失败");
        }
        return result;
    }
}
